#include<func.h>

#define N 20000000
typedef struct 
{
    int num;
    pthread_mutex_t mutex;
}data_t;


void *pthead_func(void *p)
{
    data_t *d=(data_t*)p;
    int i;
    for(i=0;i<N;i++)
    {
        pthread_mutex_lock(&d->mutex);
        d->num++;
        pthread_mutex_unlock(&d->mutex);
    }
    pthread_exit(NULL);
}

int main()
{
    pthread_t pthid;
    data_t d;
    d.num=0;
    pthread_mutex_init(&d.mutex,NULL);
    int ret=pthread_create(&pthid,NULL,pthead_func,(void*)&d);
    THREAD_ERR_CHECK(ret,"pthread_create")
    int i;
    for(i=0;i<N;i++)
    { 
        pthread_mutex_lock(&d.mutex);
        d.num++;
        pthread_mutex_unlock(&d.mutex);
        
    }
    pthread_join(pthid,NULL);
    printf("num=%d\n",d.num);
    return 0;
}